/*
 * Copyright 2009 Johnson Consulting Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 
 */
package com.johnsoncs.gwt.application.client.validation;

import java.util.HashMap;
import java.util.Map;

import com.johnsoncs.gwt.application.client.model.QueryPath;

/**
 * @author wilj
 *
 */
public class ValidationState {
	public enum Severity {
		WARN,
		ERROR
	}

	public static Map<String, String> parameters(final Object... params) {
		if (params.length % 2 == 1) {
			throw new IllegalArgumentException(
					"Sequence of key/value pairs must have an even number of elements. Elements found: "
					+ params.length);
		}

		final Map<String, String> result = new HashMap<String, String>();
		for (int i = 0; i < params.length; i += 2) {
			if (params[i] != null && params[i + 1] != null) {
				result.put(params[i].toString(), params[i + 1].toString());
			}
		}
		return result;
	}

	private String message;
	private Severity severity;
	private QueryPath path;

	private Map<String, String> parameters;

	protected ValidationState() {

	}

	/**
	 * @param message
	 * @param severity
	 */
	public ValidationState(final String message, final Severity severity, final QueryPath path,
			final Map<String, String> parameters) {
		super();
		this.message = message;
		this.severity = severity;
		this.path = path;
		this.parameters = parameters;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @return the parameters
	 */
	public Map<String, String> getParameters() {
		if (parameters == null) {
			parameters = new HashMap<String, String>();
		}
		return parameters;
	}

	/**
	 * @return the path
	 */
	public QueryPath getPath() {
		return path;
	}

	/**
	 * @return the severity
	 */
	public Severity getSeverity() {
		return severity;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(final String message) {
		this.message = message;
	}

	/**
	 * @param parameters the parameters to set
	 */
	public void setParameters(final Map<String, String> parameters) {
		this.parameters = parameters;
	}

	/**
	 * @param severity the severity to set
	 */
	public void setSeverity(final Severity severity) {
		this.severity = severity;
	}
}
